lib/commit: Fix a tmpfile fd leak in static delta processing
authorColin Walters <walters@verbum.org>
Fri, 30 Jun 2017 01:45:26 +0000 (21:45 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 30 Jun 2017 19:48:05 +0000 (19:48 +0000)
I had thought `glnx_link_tmpfile_at()` actually consumed the tmpfile;
it does consume the *path* but not the fd.  In the non-delta path
things were fine since we used the autocleanup.

But the delta code had a tmpfile allocated in its struct that got reused, and
hence leaked the fd. Fix this by making the commit API actually consume the
tmpfile fully, just like the path path.

Closes: #986
Approved by: jlebon

src/libostree/ostree-repo-commit.c

index ae3760c0088f465a30ab4e9f158d46ecee5b2c39..bc55fd6f971756b79af6e8c5da75f22a6e1d7190 100644 (file)
@@ -156,8 +156,12 @@ _ostree_repo_commit_tmpf_final (OstreeRepo        *self,
                                             cancellable, error))
     return FALSE;
 
-  return glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
-                               dest_dfd, tmpbuf, error);
+  if (!glnx_link_tmpfile_at (tmpf, GLNX_LINK_TMPFILE_NOREPLACE_IGNORE_EXIST,
+                             dest_dfd, tmpbuf, error))
+    return FALSE;
+  /* We're done with the fd */
+  glnx_tmpfile_clear (tmpf);
+  return TRUE;
 }
 
 /* Given a dfd+path combination (may be regular file or symlink),